package xyf.p01.array_nodelist;

import commons.ListNode;

import java.util.List;

/**
 * ClassName: P0203_RemoveElements
 * Description:
 * Author: xyf
 * Date: 9/1/22 10:31 PM
 * Version: 1.0
 **/
public class P0203_RemoveElements
{
    public ListNode removeElements(ListNode head, int val)
    {
        if (null == head)
        {
            return null;
        }

        ListNode dummyHead = new ListNode();
        dummyHead.next = head;
        ListNode cur = dummyHead;
        while (cur.next != null)
        {
            if (cur.next.val == val)
            {
                cur.next = cur.next.next;
            }
            else
            {
                cur = cur.next;
            }

        }
        return dummyHead.next;

    }
}